#!/bin/bash
#get this script real directory
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

env_file=$this_script_dir/../nat_type_checker/service/env.sh
source $env_file

if [ -n "$1" ] ; then
    if [ ! -d "$1" ] ; then
        echo "-- error, your set parameter $1, the path does not exist."
        exit 1 
    fi
fi

if [ -z "$1" ] && [ -z "$p2pcpp_home" ]; then
    echo "-- error, usage $0 /path_of_p2pcpp_installed"
    echo "          or set environment p2pcpp_home=/path_of_p2pcpp_installed into ~/.bashrc"
    exit 1 
else
    set_env $1
fi


log_file=$log_dir/check_nat_type_and_update_`date +%Y-%m-%d`.log
echo "-- info, log_file is:$log_file"

which p2pcpp
if [ $? -ne 0 ] ; then
    echo "-- error, can not found p2pcpp, please check wheather $bin_dir/p2pcpp exist."
    exit 1 
fi

log_file=$log_dir/server_multiple_port_`date +%Y-%m-%d`.log
echo "--info,`date "+%Y-%m-%d %H:%M:%S"` start_p2pcpp  p2pcpp_home is:$p2pcpp_home" | tee -a $log_file
nohup which p2pcpp && p2pcpp -t suite_udp_multiple/case_test_server 2>&1 | tee -a $log_file  &


